šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Book a DemoInstallSign in
Socket

json-diff

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-diff

JSON diff

1.0.6
latest
Source
npm
Version published
Weekly downloads
742K
-12.54%
Maintainers
2
Weekly downloads
Ā 
Created

What is json-diff?

The json-diff npm package is a tool for comparing JSON objects and generating a diff between them. It is useful for identifying changes between two JSON structures, which can be helpful in various scenarios such as configuration management, data synchronization, and debugging.

What are json-diff's main functionalities?

Generate Diff

This feature allows you to generate a diff between two JSON objects. The code sample demonstrates how to use the json-diff package to compare two JSON objects and print the differences.

const jsonDiff = require('json-diff');
const oldJson = { name: 'Alice', age: 25 };
const newJson = { name: 'Alice', age: 26 };
const diff = jsonDiff.diffString(oldJson, newJson);
console.log(diff);

Pretty Print Diff

This feature allows you to generate a color-coded diff for better readability. The code sample shows how to enable color in the diff output.

const jsonDiff = require('json-diff');
const oldJson = { name: 'Alice', age: 25 };
const newJson = { name: 'Alice', age: 26 };
const diff = jsonDiff.diffString(oldJson, newJson, { color: true });
console.log(diff);

Compare JSON Files

This feature allows you to compare JSON data from files. The code sample demonstrates how to read JSON data from two files and generate a diff.

const fs = require('fs');
const jsonDiff = require('json-diff');
const oldJson = JSON.parse(fs.readFileSync('old.json', 'utf8'));
const newJson = JSON.parse(fs.readFileSync('new.json', 'utf8'));
const diff = jsonDiff.diffString(oldJson, newJson);
console.log(diff);

Other packages similar to json-diff

FAQs

Package last updated on 15 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts